package com.jyw.web.controller.system;

import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.enums.BusinessType;
import com.jyw.common.utils.poi.ExcelUtil;
import com.jyw.system.domain.SysFormConfigColumn;
import com.jyw.system.service.ISysFormConfigColumnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 系统表单配置字段Controller
 *
 * @author ZhangCheng
 * @date 2023-08-10
 */
@Api(tags = "系统表单配置字段Api")
@RestController
@RequestMapping("/system/formConfigColumn")
public class SysFormConfigColumnController extends BaseController {

    @Autowired
    private ISysFormConfigColumnService sysFormConfigColumnService;

    /**
     * 查询系统表单配置字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:formConfigColumn:list')")
    @GetMapping("/list")
    @ApiOperation("查询系统表单配置字段列表")
    public TableDataInfo<SysFormConfigColumn> list(SysFormConfigColumn sysFormConfigColumn) {
        startPage();
        List<SysFormConfigColumn> list = sysFormConfigColumnService.selectSysFormConfigColumnList(sysFormConfigColumn);
        return getDataTable(list);
    }

    /**
     * 导出系统表单配置字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:formConfigColumn:export')")
    @Log(title = "系统表单配置字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出系统表单配置字段列表")
    public void export(HttpServletResponse response, SysFormConfigColumn sysFormConfigColumn) {
        List<SysFormConfigColumn> list = sysFormConfigColumnService.selectSysFormConfigColumnList(sysFormConfigColumn);
        ExcelUtil<SysFormConfigColumn> util = new ExcelUtil<SysFormConfigColumn>(SysFormConfigColumn.class);
        util.exportExcel(response, list, "系统表单配置字段数据");
    }

    /**
     * 获取系统表单配置字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:formConfigColumn:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取系统表单配置字段详细信息")
    public CommonResult<SysFormConfigColumn> getInfo(@PathVariable("id") Long id) {
        return CommonResult.success(sysFormConfigColumnService.selectSysFormConfigColumnById(id));
    }

    /**
     * 根据配置主表id获取系统表单配置字段
     */
    @GetMapping(value = "/queryListByFormId")
    @ApiOperation("根据配置主表id获取系统表单配置字段")
    public CommonResult<List<SysFormConfigColumn>> queryListByFormId(Long formId) {
        return CommonResult.success(sysFormConfigColumnService.selectByFormId(formId));
    }

    /**
     * 新增系统表单配置字段
     */
    @PreAuthorize("@ss.hasPermi('system:formConfigColumn:add')")
    @Log(title = "系统表单配置字段", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    @ApiOperation("新增系统表单配置字段")
    public CommonResult add(@RequestBody SysFormConfigColumn sysFormConfigColumn) {
        return CommonResult.success(sysFormConfigColumnService.insertSysFormConfigColumn(sysFormConfigColumn));
    }

    /**
     * 修改系统表单配置字段
     */
    @PreAuthorize("@ss.hasPermi('system:formConfigColumn:edit')")
    @Log(title = "系统表单配置字段", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    @ApiOperation("修改系统表单配置字段")
    public CommonResult edit(@RequestBody SysFormConfigColumn sysFormConfigColumn) {
        return CommonResult.success(sysFormConfigColumnService.updateSysFormConfigColumn(sysFormConfigColumn));
    }

    /**
     * 批量修改系统表单配置字段
     */
    @Log(title = "批量修改系统表单配置字段", businessType = BusinessType.UPDATE)
    @PutMapping("/updateList")
    @ApiOperation("批量修改系统表单配置字段")
    public CommonResult editList(@RequestBody List<SysFormConfigColumn> columns) {
        sysFormConfigColumnService.updateColumnList(columns);
        return CommonResult.success();
    }

    /**
     * 删除系统表单配置字段
     */
    @PreAuthorize("@ss.hasPermi('system:formConfigColumn:remove')")
    @Log(title = "系统表单配置字段", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除系统表单配置字段")
    public CommonResult remove(@PathVariable Long[] ids) {
        return CommonResult.success(sysFormConfigColumnService.deleteSysFormConfigColumnByIds(ids));
    }
}
